/**
 * Project Name:fire-industry-DM-center
 * File Name:ReturnDTO.java
 * Package Name:com.firestone.bean.dto
 * Date:2018年3月12日下午2:48:22
 *
*/

package com.firestone.bean.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.firestone.core.enums.SystemCodeEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @Description: TODO(API返回的 数据模型)
 * @author CAIYJ
 * @date 2018年3月12日 下午2:48:22
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel
public class ReturnDTO<T> {

    /**
     * @Fields code : TODO(返回码)
     */
    @ApiModelProperty(value = "状态码 200表示成功；其他表示失败", example = "状态码 200表示成功；其他表示失败")
    private Integer status;

    /**
     * @Fields error : TODO(返回异常信息)
     */
    @ApiModelProperty(value = "错误信息", example = "错误信息")
    private String error;

    /**
     * @Fields message : TODO(返回信息)
     */
    @ApiModelProperty(value = "返回提示信息", example = "返回提示信息")
    private String message;

    /**
     * @Fields data : TODO(返回结果集)
     */
    @ApiModelProperty(value = "数据", example = "")
    private T data;

    public ReturnDTO() {
        super();
    }

    public ReturnDTO(Integer status, String error, String message, T data) {
        super();
        this.status = status;
        this.error = error;
        this.message = message;
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ReturnDTO<T> success(T data) {
        return new ReturnDTO<T>(SystemCodeEnum.getCode("SUCCESS"), null, null,
                data);
    }

    @SuppressWarnings("unchecked")
    public static <T> ReturnDTO<T> fail(SystemCodeEnum systemCodeEnum) {
        return new ReturnDTO<T>(systemCodeEnum.getErrorCode(),
                systemCodeEnum.getErrorMsg(), systemCodeEnum.getErrorMsg(),
                (T) systemCodeEnum.getErrorMsg());
    }

}
